ImageController = Class.create();
ImageController.prototype = {
	initialize: function(){
		this.batch = [];
		this.space = $('image_controller_space');
		this.input_field = $('selected_ids')
		this.hide_batch();
	},
	show_batch: function(){
		this.space.show();
	},
	hide_batch: function(){
		this.space.hide();
	},
	clear_batch: function(){
		this.batch.each(function(el){
			this.remove_batch(el);
		}.bind(this))
	},
	add_batch: function(image_id){
		if (!(this.is_in_batch(image_id))){
			this.batch.push(image_id);
		}
		$('image_link_'+image_id).addClassName('clicked');
		this.input_field.value = this.batch.join(',');
		this.space.innerHTML = "You chose image(s) #" + this.batch.join(',');
		//this.show_batch();
	},
	remove_batch: function(image_id){
		this.batch = this.batch.without(image_id);
		$('image_link_'+image_id).removeClassName('clicked');
		this.input_field.value = this.batch.join(',');
		this.space.innerHTML = "You chose image(s) #" + this.batch.join(',');
	},
	toggle_batch: function(image_id){
		if (this.is_in_batch(image_id)){
			this.remove_batch(image_id);
		} else {
			this.add_batch(image_id);
		}
	},
	batch_size: function(){
		return this.batch.length;
	},
	is_in_batch: function(image_id){
		var is_found = this.batch.any(function(el){
			return el == image_id;
		});
		return is_found;
	},
	image_tag: function(image_id){
		//how to handle image_id and image_filename?
		return '<img src="/pictures/'+image_id+' />'
	},
	update_from_field: function(){
		if(this.input_field.value == '') return;
		new_batch = this.input_field.value.split(',');
		new_batch.each(function(el){
			this.add_batch(el);
		}.bind(this))
	}
}